package com.cm.caseManagement.controller;


import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmSysRoleMenu;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmSysRoleMenuService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色菜单关联Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/roleMenu")
public class CmSysRoleMenuController extends BaseController
{
    @Autowired
    private ICmSysRoleMenuService cmSysRoleMenuService;

    /**
     * 查询角色菜单关联列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmSysRoleMenu cmSysRoleMenu)
    {
        startPage();
        List<CmSysRoleMenu> list = cmSysRoleMenuService.selectCmSysRoleMenuList(cmSysRoleMenu);
        return getDataTable(list);
    }

    /**
     * 导出角色菜单关联列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:export')")
    @Log(title = "角色菜单关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmSysRoleMenu cmSysRoleMenu)
    {
        List<CmSysRoleMenu> list = cmSysRoleMenuService.selectCmSysRoleMenuList(cmSysRoleMenu);
        ExcelUtil<CmSysRoleMenu> util = new ExcelUtil<CmSysRoleMenu>(CmSysRoleMenu.class);
        util.exportExcel(response, list, "角色菜单关联数据");
    }

    /**
     * 获取角色菜单关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmSysRoleMenuService.selectCmSysRoleMenuById(id));
    }

    /**
     * 新增角色菜单关联
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:add')")
    @Log(title = "角色菜单关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmSysRoleMenu cmSysRoleMenu)
    {
        return toAjax(cmSysRoleMenuService.insertCmSysRoleMenu(cmSysRoleMenu));
    }

    /**
     * 修改角色菜单关联
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:edit')")
    @Log(title = "角色菜单关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmSysRoleMenu cmSysRoleMenu)
    {
        return toAjax(cmSysRoleMenuService.updateCmSysRoleMenu(cmSysRoleMenu));
    }

    /**
     * 删除角色菜单关联
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:remove')")
    @Log(title = "角色菜单关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmSysRoleMenuService.deleteCmSysRoleMenuByIds(ids));
    }
}
